using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    class MRPProductTypesService 
    {
        ISession session;

        public MRPProductTypesService(ISession session)
        {
            this.session = session;
        }
        public MRPProductTypesService()
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrpproducttypes(MRPProductTypes mrpproducttypesX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpproducttypesX);
            tx.Commit();
        }

        public void UpdateMrpproducttypes(MRPProductTypes mrpproducttypesX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpproducttypesX);
            tx.Commit();
        }

        public void DeleteMrpproducttypes(MRPProductTypes mrpproducttypesX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpproducttypesX);
            tx.Commit();
        }

        public IList<MRPProductTypes> GetAllMrpproducttypes(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPProductTypes");
            IList<MRPProductTypes> list = query.List<MRPProductTypes>();
            if (evict)
            {
                foreach (MRPProductTypes s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPProductTypes GetAllMrpproducttypesByID(String id,Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPProductTypes as c where c.Producttypeid= :x");
            query.SetString("x", id);
            MRPProductTypes s = (MRPProductTypes)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPProductTypes> GetMrpproducttypesByQuery(IQuery query,Boolean evict)
        {
            IList<MRPProductTypes> list = query.List<MRPProductTypes>();
            if (evict)
            {
                foreach (MRPProductTypes s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
